----------------------------------------------------------------
-- Global Variables
----------------------------------------------------------------

EA_Window_ROCPopup = {}

----------------------------------------------------------------
-- Local Variables
----------------------------------------------------------------

----------------------------------------------------------------
-- EA_Window_ROCPopup Functions
----------------------------------------------------------------

function EA_Window_ROCPopup.Initialize()       

    LabelSetText( "EA_Window_ROCPopupTitleBarText", GetPregameString( StringTables.Pregame.LABEL_ROC_TITLE))
    ButtonSetText("EA_Window_ROCPopupAcceptButton", GetPregameString( StringTables.Pregame.LABEL_PRESELECT_ACCEPT ))
    ButtonSetText("EA_Window_ROCPopupDeclineButton", GetPregameString( StringTables.Pregame.LABEL_PRESELECT_DECLINE ))
    LabelSetText( "EA_Window_ROCPopupAgreeCheckboxLabel", GetPregameString( StringTables.Pregame.LABEL_ROC_CHECKBOX))
    ButtonSetCheckButtonFlag("EA_Window_ROCPopupAgreeCheckbox", true)

    -- disable the accept button and the checkbox initially
    ButtonSetDisabledFlag("EA_Window_ROCPopupAcceptButton", true)

    EA_Window_ROCPopup.CreateTextBody()
end

function EA_Window_ROCPopup.Shutdown()
end

function EA_Window_ROCPopup.Show()
    WindowSetShowing("EA_Window_ROC", true)
end

function EA_Window_ROCPopup.ToggleShowing()
    local showing = WindowGetShowing("EA_Window_ROC")
    WindowSetShowing("EA_Window_ROC", not showing)
end

function EA_Window_ROCPopup.Accept()
    -- don't do anything if the checkbox hasn't been checked
    if (ButtonGetDisabledFlag("EA_Window_ROCPopupAcceptButton"))
    then
        return
    end

    BroadcastEvent( SystemData.Events.PREGAME_ROC_ACCEPTED )
    WindowSetShowing("EA_Window_ROC", false)
    
    SettingsWindowTabbed.DoLoginPerformanceWarning()
    
end

function EA_Window_ROCPopup.Decline()
    WindowSetShowing("EA_Window_ROC", false)
    -- if you don't accept then we will quit the game
    BroadcastEvent( SystemData.Events.QUIT )
end

function EA_Window_ROCPopup.CreateTextBody()
    TextLogDestroy("ROCLog")
    TextLogCreate("ROCLog", #StringTables.ROC)
    TextLogAddFilterType("ROCLog", 1, L"")
    LogDisplayAddLog("EA_Window_ROCPopupLogDisplay", "ROCLog", true)
    LogDisplaySetShowTimestamp("EA_Window_ROCPopupLogDisplay", false)
    LogDisplaySetShowLogName("EA_Window_ROCPopupLogDisplay", false)
    TextLogDisplayShowScrollbar("EA_Window_ROCPopupLogDisplay", true)

    for index = 0, #StringTables.ROC
    do
        TextLogAddEntry("ROCLog", 1, GetStringFromTable("ROC", index))
    end

    LogDisplayScrollToTop("EA_Window_ROCPopupLogDisplay")

end

function EA_Window_ROCPopup.ToggleAgreeCheckbox()
    -- don't do anything if the checkbox hasn't been enabled
    if (ButtonGetDisabledFlag("EA_Window_ROCPopupAgreeCheckbox"))
    then
        return
    end

    local toggleIsPressed = ButtonGetPressedFlag("EA_Window_ROCPopupAgreeCheckbox")
    ButtonSetDisabledFlag("EA_Window_ROCPopupAcceptButton", not toggleIsPressed)
end

function EA_Window_ROCPopup.ToggleAgreeCheckboxFromLabel()
    -- don't do anything if the checkbox hasn't been enabled
    if (ButtonGetDisabledFlag("EA_Window_ROCPopupAgreeCheckbox"))
    then
        return
    end

    local toggleIsPressed = ButtonGetPressedFlag("EA_Window_ROCPopupAgreeCheckbox")
    ButtonSetPressedFlag("EA_Window_ROCPopupAgreeCheckbox", not toggleIsPressed)
    EA_Window_ROCPopup.ToggleAgreeCheckbox()
end

function EA_Window_ROCPopup.MouseOverCheckboxLabel()
    -- don't do anything if the checkbox hasn't been enabled
    if (ButtonGetDisabledFlag("EA_Window_ROCPopupAgreeCheckbox"))
    then
        return
    end

    LabelSetTextColor("EA_Window_ROCPopupAgreeCheckboxLabel", DefaultColor.YELLOW.r, DefaultColor.YELLOW.g, DefaultColor.YELLOW.b)
end

function EA_Window_ROCPopup.MouseOverEndCheckboxLabel()
    -- don't do anything if the checkbox hasn't been enabled
    if (ButtonGetDisabledFlag("EA_Window_ROCPopupAgreeCheckbox"))
    then
        return
    end

    LabelSetTextColor("EA_Window_ROCPopupAgreeCheckboxLabel", DefaultColor.WHITE.r, DefaultColor.WHITE.g, DefaultColor.WHITE.b)
end